package dobest.ray.com.jiongjiong.activity.login.dataInport.questionair;


import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import java.util.List;

import dobest.ray.com.jiongjiong.R;
import dobest.ray.com.jiongjiong.activity.BaseFragment;
import dobest.ray.com.jiongjiong.bean.QuestionairCallBackBean;
import dobest.ray.com.jiongjiong.bean.QuestionnairBean;
import dobest.ray.com.jiongjiong.callback.A2FCallBack;

/**
 * 日常训练
 */

public class QuestionnairFragment extends BaseFragment implements
        OnClickListener {
    private ListView ls_question;
    private int index = -1;
    private TextView tv_submit;
    private QuestionnairAdapter adapter;
    private Activity activity;
    private A2FCallBack<QuestionairCallBackBean> callBack;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        activity = getActivity();
        if (activity instanceof A2FCallBack) {
            callBack = (A2FCallBack<QuestionairCallBackBean>) activity;
        }
        return inflater.inflate(R.layout.fragment_questionnair, null);
    }


    public List<QuestionnairBean> getData() {
        return adapter.getData();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
//		case R.id.richang_03:
//			Intent intent = new Intent(getActivity(),
//					MuMingLeShiHomePagerActivity.class);
//			startActivity(intent);
//			break;

            default:
                break;
        }
    }

    @Override
    protected void findViews(View view) {
        ls_question = (ListView) view.findViewById(R.id.ls_question);
    }

    @Override
    protected void init() {
        index = getArguments().getInt("index");
        if (index == 3) {
            View footView = LayoutInflater.from(activity).inflate(
                    R.layout.foot_view_check, null);
            ls_question.addFooterView(footView);
            tv_submit = (TextView) footView.findViewById(R.id.tv_submit);
            tv_submit.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (callBack != null) {
                        callBack.getActivityData(new QuestionairCallBackBean("confirm_survey", 0));
                    }
//					EventBus.getDefault().post(
//							new EventbusBean("confirm_survey", 0));

                }
            });
        }
        adapter = new QuestionnairAdapter(activity, index, callBack);
        ls_question.setAdapter(adapter);
    }

    @Override
    protected void addListeners() {

    }
}
